package helpers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UrlHelper {
	public static String createUrl(String str, String type, HttpServletRequest request) {
		HttpSession session = request.getSession(true);
		@SuppressWarnings("deprecation")
		String limit = (String) session.getValue("limit");
		@SuppressWarnings("deprecation")
		String country = (String) session.getValue("country");
		@SuppressWarnings("deprecation")
		String feedType = (String) session.getValue("feedType");
		@SuppressWarnings("deprecation")
		String genre = (String) session.getValue("genre");
		
		String url = "";
		
		if (type.equalsIgnoreCase("country")) {
			url += "country=" + str;
		} else {
			url += "country=" + country;
		}
		
		if (type.equalsIgnoreCase("limit")) {
			url += "&limit=" + str;
		} else {
			url += "&limit=" + limit;
		}
		
		if (type.equalsIgnoreCase("feedType")) {
			url += "&type=" + str;
		} else {
			url += "&type=" + feedType;
		}
		
		if (type.equalsIgnoreCase("genre")) {
			if (!str.equalsIgnoreCase("0")) {
				url += "&genre=" + str;
			}
		} else {
			if (genre!= null && !genre.equalsIgnoreCase("0")) {
				url += "&genre=" + genre;
			}
		}

		return url;
	}
}
